<template>
	<view>
		<!-- 搜索组件吸顶设置 -->
		<view class="search">
				<my-serch  @click="gotoSearch"></my-serch>
		</view>
		
		<!-- //8.渲染列表数据 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular>
			<swiper-item v-for="(item,index) in swiperList" :key="item.id">
				<navigator class="swiper-item" :url="`/subpkg/goods_detail/goods_detail?goods_id=${item.goods_id}`">
					<image :src="item.image_src" mode="widthFix"></image>
				</navigator>
			</swiper-item>
			
		</swiper>
		<!-- //10.渲染navList数据 -->
		<view class="navList">
				<view class="navItem" v-for="(item,index) in navList" :key="index" @click="navCate(item)"> 
						<image :src="item.image_src" mode="widthFix"></image>
						
				</view>
		</view>
		<!-- 渲染楼层的标题 -->
		<view class="foolList">
				<view class="foolItem" v-for="(item,i ) in footList" :key="i">
					<image :src="item.floor_title.image_src" mode="widthFix"></image>
					<view class="fool_box ">
						<!-- 左边 -->
						<navigator class="fool_box_left" :url="item.product_list[0].url">
							<image :src="item.product_list[0].image_src" mode="widthFix" :style="{width:item.product_list[0].image_width+'rpx'}"></image>
						</navigator>
						<!-- 右边 -->
						<view class="fool_box_right">
							<navigator class="fool_box_right_item"  v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2 !=0" :url="item2.url">
									<image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width+'rpx'}"></image>
							</navigator>
						</view>
					</view>
				</view>
		</view>
	</view>
</template>

<script>
	import setBrage from "@/mixins/tabbar_badge.js"
	export default {
		
		data() {
			return {
				//1.定义这是轮播图的数据列表
				swiperList:[],
				//7.定义navList 装数据
				navList:[],
				//9.定义楼层数数据
				footList:[]
			};
		},
		mixins:[setBrage],
		onLoad(){
			//3.调用方法，获取轮播图的数据
			console.log("页面加载了")
			this.getSwiperList();
			//8.调用方法 获取navList数据
			this.getnavList();
			//10.调用获取楼层的数据
			this.getfoolList();
		},
		methods:{
			//2.定义一个获取数据的方法
			async getSwiperList(){
				
				const {data:res}= await uni.$http.get("/api/public/v1/home/swiperdata");
				//4.判断是否请求成功
				
				//5.请求失败的消息
				if(res.meta.status != 200) {
					return uni.$showMsg()
					
				}
				//6.请求成功的数据赋值
				this.swiperList = res.message;
				
				
				
				
			},
			//9.定义getnavList 方法
			async getnavList(){
				const  {data:res} = await uni.$http.get("/api/public/v1/home/catitems");
				console.log(res);
				if(res.meta.status != 200){
					uni.$showMsg();
				}
				this.navList = res.message;
			},
			//11.定义获取楼层的数据
			async getfoolList(){
				const {data:res} = await uni.$http.get("/api/public/v1/home/floordata");
				if(res.meta.status != 200){
					return uni.$showMsg();
				}
				//12对返回的数据进行处理
				res.message.forEach(floor=>{
					floor.product_list.forEach(prod=>{
						prod.url="/subpkg/goods_list/goods_list?"+prod.navigator_url.split("?")[1]
					})
				})
				this.footList = res.message;
					
			},
			navCate(item){
				console.log(item);
				if(item.name === "分类"){
					uni.switchTab({
						url:"/pages/cate/cate"
					})
				}
				
			},
			gotoSearch(){
				uni.navigateTo({
					url:"/subpkg/search/search"
				})
			}
		}
	}
</script>

<style lang="scss">
	swiper-item image{
		width: 100%;
		height: 330rpx ;
	}
	*{
		magrin:0;
		padding:0
	}
	
	.navList  {
			display: flex;
			justify-content: space-around;
			align-items: center;
			margin:15rpx 0; 
			margin-top: 20rpx;
			
			.navItem{
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				
				image {
					width: 60%;
				}
				
			}
	}
	.foolItem{
		image{
			width: 100%;
		}
	}
	.fool_box {
		padding:0 15rpx;
		width: 100%;
		box-sizing: border-box;
		display: flex;
		justify-content:space-between;
		align-items: flex-start;
	}
	
	.fool_box_right {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		
	}
	
	.fool_box_right_item {
		border-radius: 20rpx;
		overflow: hidden;
		padding-top:2rpx;
	}
	.foolList {
		margin-top:20rpx;
	}
	.foolItem{
		marin-top:20rpx;
	}
	.search{
		width: 100%;
		position: sticky;
		top: 0;
		z-index: 99;
	}
	swiper{
		height: 190px;
	}
	swiper-item{
		height: auto !important;
	}
</style>
